package com.example.validation;

//import jakarta.validation.ConstraintValidator;
//import jakarta.validation.ConstraintValidatorContext;

import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;

import java.util.List;

public class NotEmptyOrNullListValidator implements ConstraintValidator<NotEmptyOrNullList, List<?>> {

    @Override
    public void initialize(NotEmptyOrNullList constraintAnnotation) {
    }

    @Override
    public boolean isValid(List<?> list, ConstraintValidatorContext context) {
        if (list == null || list.isEmpty()) {
            return true; // 允许为空列表或null
        }
        for (Object item : list) {
            if (item == null || item.toString().trim().isEmpty()) {
                return false; // 如果有null元素，则返回false
            }
            if (!(item instanceof String)) {
                return false;
            }
        }
        return true; // 所有元素都不为null
    }
}
